//
//  AFFAppSettings.m
//  AnyfishApp
//
//  Created by apple on 14-3-21.
//  Copyright (c) 2014年 Anyfish. All rights reserved.
//

#import "AFFAppSettings.h"
#import "UIApplication+Permissions.h"
#import <AVFoundation/AVFoundation.h>
#import <CoreMotion/CoreMotion.h>

@interface AFFAppSettings() {

}

@end

@implementation AFFAppSettings

static AFFAppSettings *defaultAppSettings;

+ (AFFAppSettings *) sharedInstance {

    
    if (!defaultAppSettings) {
        AFFAppSettings *setting = [[AFFAppSettings alloc] init];
        NSString *configNameFull = [setting fileNameConfig_Full];
        NSFileManager *manager = [NSFileManager defaultManager];
        if(![manager fileExistsAtPath:configNameFull]){
//            [FileHelper writeModeToFile:setting];
        }else{
//            setting = [AFFAppSettings objectWithFile:configNameFull];
        }
        
        defaultAppSettings = setting;
        [defaultAppSettings updateRealtime];
        defaultAppSettings.lastTaskHourCheekTime = 0;
        
        // 更新多发行先关配置
        [kSetting initPlist];
    }

    return defaultAppSettings;
}

+ (void)cleanAppSetting {
    AFFAppSettings *setting = [[AFFAppSettings alloc] init];
    NSString *configNameFull = [setting fileNameConfig_Full];
//    if([FileHelper isFileExist:configNameFull]){
//        [FileHelper deleteFileAtPath:configNameFull];
//    }
    defaultAppSettings = nil;
}

- (id)init {
    self = [super init];
    if(self){
        [self setDefaultValue];
    }
    
    return self;
}

- (void)setDefaultValue{
    self.showAssistAlert = YES;
    self.showPartAssistAlert = YES;
    self.showBegAlert = YES;
    self.showWorkAlert = YES;
    self.showCoinAlert = YES;
    self.showCommentAlert = YES;
    self.showWorkfireAlert = YES;
    self.showReplyAlert = YES;
    self.showPartReplyAlert = YES;
    self.showTouchAlert = YES;
    self.showGiftTouchAlert = YES;
    self.showDiaryVoteAlert = YES;
    self.showPresentAlert = YES;
    self.showServiceAlert = YES;
    self.showServiceLocalAlert = YES;
    self.showOtherFishAlert = YES;
    self.showGiftRoomFeedAlert = YES;
    self.showPoleWaterUsingAlert = YES;
    self.showMallNoticeAlert = YES;
    self.isLeftHandFirst = YES;
    self.isFirstLogin = YES;
    self.showWorkDiaryCheckAlert = YES;
    self.showExpenseFishAlert = YES;
    self.showMissionOutAlert = YES;
    self.showStepWarnAlert = YES;
    self.showJinlongFishAlert = YES;
    self.showFreeFishAler = YES;
    
    self.cache_Pool_RobID = @"101";
    self.cache_Pool_RobPet = @"201";
    
    self.cachePoolPushPet = @"0";
    self.cachePoolPushBag = @"0";
    
    self.cacheBuddhaPestle = @"0";
    self.cacheBuddhaIncense = @"0";
    self.cacheBuddhaIncenseText = @"0";
    
    
    self.cacheCalendarDispDate = @"0";
    self.cacheNetsShareFishDispDate = @"0";
    
    self.cacheSelectRoleEntityCode = @"";
    self.cacheBillLastPrinterGUID = @"";
    self.cacheBillInvitionCode = @"0";
    self.cacheBillEntityCode = @"";
    self.cacheCollectionTimeDispDate = @"0";
    self.cacheTowerPlayCardsCountdown = @"";

    self.cacheWalkEndTime = 0;
    
    self.cacheBrushPictureCount = @"0";
}

- (void)updateRealtime {
    self.hasNewSystem = NO;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if(object==defaultAppSettings){
        // 发生变化需要保存到文件
//        [FileHelper writeModeToFile:defaultAppSettings];
    }
}

- (NSString*)fileNameConfig_Full {
    return [NSString stringWithFormat:@"%@/AppSetting_config.txt", [self configPath_Full]];
}



#pragma mark getter

- (BOOL)hasNew_LeftPanel {
    return _hasNew_Friend || _hasNew_Setting;
}

+ (void)alertWarning:(NSString *)name{
//    [AFFAlertView alertWithTitle:[NSString stringWithFormat:@"无法使用%@\n请在iPhone的\"设置-隐私-%@\"中允许%@访问您的%@",name,name,kSetting.issuer.nameApp,name] btnTitle:@[@"确定"] block:^(NSInteger index, BOOL isCancel) {
//        [AFFAlertView dismiss];
//    }];
}

+ (void)isAddrassBookAvailable:(PermissionsRequest)block {
    kPermissionAccess accType = [[UIApplication sharedApplication] hasAccessToContacts];
    if(accType == kPermissionAccessGranted){
        block(YES);
    }else if(accType == kPermissionAccessNotRequest){
        [[UIApplication sharedApplication] requestAccessToContactsWithSuccess:^{
            WORK_MAIN(^{
                block(YES);
            });
        } andFailure:^{
            WORK_MAIN(^{
                [AFFAppSettings alertWarning:@"通讯录"];
                block(NO);
            });
        }];
    }else if(accType == kPermissionAccessDenied) {
        [AFFAppSettings alertWarning:@"通讯录"];
    }
}

+ (void)isPhotosAvailable:(PermissionsRequest)block {
    kPermissionAccess accType = [[UIApplication sharedApplication] hasAccessToPhotos];
    if(accType == kPermissionAccessGranted){
        block(YES);
    }else if(accType == kPermissionAccessNotRequest){
        [[UIApplication sharedApplication] requestAccessToPhotosWithSuccess:^{
            WORK_MAIN(^{
                block(YES);
            });
        } andFailure:^{
            WORK_MAIN(^{
                [AFFAppSettings alertWarning:@"相册"];
                block(NO);
            });
        }];
    }else if(accType == kPermissionAccessDenied) {
        [AFFAppSettings alertWarning:@"相册"];
        block(NO);
    }
}

+ (void)isCameraAvailable:(PermissionsRequest)block {
    kPermissionAccess accType = [[UIApplication sharedApplication] hasAccessToCamera];
    if(accType == kPermissionAccessGranted){
        block(YES);
    }else if(accType == kPermissionAccessNotRequest){
        [[UIApplication sharedApplication] requestAccessToCameraWithSuccess:^{
            WORK_MAIN(^{
                block(YES);
            });
        } andFailure:^{
            WORK_MAIN(^{
                [AFFAppSettings alertWarning:@"相机"];
                block(NO);
            });
        }];
    }else {
        [AFFAppSettings alertWarning:@"相机"];
        block(NO);
    }
}

+ (void)isGPSAvailable:(BOOL)alert block:(PermissionsRequest)block {
    kPermissionAccess accType = [[UIApplication sharedApplication] hasAccessToLocation];
    if(accType == kPermissionAccessGranted){
        block(YES);
    }else if(accType == kPermissionAccessNotRequest){
        [[UIApplication sharedApplication] requestAccessToLocationWithSuccess:^{
            WORK_MAIN(^{
                block(YES);
            });
        } andFailure:^{
            block(NO);
        }];
    }else if(accType == kPermissionAccessDenied) {
        block(NO);
        if(alert)
            [AFFAppSettings alertWarning:@"定位服务"];
    }
}

+ (void)isBluetoothAvailable:(PermissionsRequest)block {
    [self isBluetoothAvailable:YES block:block];
}

+ (void)isBluetoothAvailable:(BOOL)alert block:(PermissionsRequest)block {
    kPermissionAccess ka = [[UIApplication sharedApplication] hasAccessToBluetoothLE];
    
    if(ka == kPermissionAccessGranted ||
       ka == kPermissionAccessRestricted){
        block(YES);
    }else if(ka == kPermissionAccessDenied ){
        if(alert)
            [AFFAppSettings alertWarning:@"蓝牙"];
        block(NO);
    }else if(ka == kPermissionAccessNotRequest){
        block(YES);
    }else {
        if(alert)
        block(NO);
    }
}

+ (void)isMicrophoneAvailable:(PermissionsRequest)block {
    [[UIApplication sharedApplication] requestAccessToMicrophoneWithSuccess:^{
        WORK_MAIN(^{
            block(YES);
        });
    } andFailure:^{
        WORK_MAIN(^{
            [AFFAppSettings alertWarning:@"麦克风"];
            block(NO);
        });
    }];
}

+ (void)isActivityAvailable:(PermissionsRequest)block {
    CMStepCounter *counter = [[CMStepCounter alloc] init];
    [counter queryStepCountStartingFrom:[NSDate date]
                                     to:[NSDate date]
                                toQueue:[[NSOperationQueue alloc] init]
                            withHandler:^(NSInteger numberOfSteps, NSError * _Nullable error) {
                                WORK_MAIN(^{
                                    block(error==nil);
                                });
                            }];
}

+ (void)isStepCountingAvailable:(PermissionsRequest)block {
    block(IOS_VERSION<8.0?NO:[CMPedometer isStepCountingAvailable]);
}

+ (void)dispose{
    defaultAppSettings = nil;
}

- (void)setValueForKey:(NSString *)key boolValue:(BOOL)value{
    if([NSString isNilOrEmpty:key]){
        NSLog(@"key 怎么会没有");
        return;
    }
    
    [self setValueForKey:key stringValue:value?@"1":@"0"];
}

- (void)setValueForKey:(NSString *)key stringValue:(NSString *)value{
    if([NSString isNilOrEmpty:key] || [NSString isNilOrEmpty:value]){
        NSLog(@"key 怎么会没有");
        return;
    }
    
    BOOL saveToDB = YES;
    AFFAppSettings *settings = [AFFAppSettings sharedInstance];
    if([key isEqualToString:kLocal_IsMicro]){
        settings.isMicro = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_HasUnreadYulong]){
        settings.hasUnreadYulong = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_HasUnreadYuzai]){
        settings.hasUnreadYuzai = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_HasUnreadCircle]){
        settings.hasUnreadCircle = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_HasUnreadTide]){
        settings.hasUnreadTide = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_HasUnreadFacespotFishChange]){
        settings.hasUnreadFacespotFishChange = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_HasNewSystem]){
        saveToDB = NO;
        settings.hasNewSystem = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_LastTaskDailyCheekTime]){
        settings.lastTaskDailyCheekTime = [value intValue];
        
    }else if([key isEqualToString:kLocal_LastTaskRadioCheekTime]){
        settings.lastTaskRadioCheekTime = [value intValue];
        
    }else if([key isEqualToString:kLocal_LastTaskHourCheekTime]){
        settings.lastTaskHourCheekTime = [value intValue];
        saveToDB = NO;
        
    }else if([key isEqualToString:kLocal_VersionStatus]){
        settings.versionStatus = [value integerValue];
        
    }else if([key isEqualToString:kLocal_NewSystemDesc]){
        saveToDB = NO;
        settings.nSystemDesc = value?value:@"";
        
    }else if([key isEqualToString:kLocal_VersionIgnore]){
        settings.isVersionIgnore = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Comment]){
        settings.showCommentAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Workfire])
    {
        settings.showWorkfireAlert = [value intValue]>0;
    }
    else if([key isEqualToString:kLocal_Alert_Reply]){
        settings.showReplyAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Part_Reply]){
        settings.showPartReplyAlert = [value intValue]>0;

    }else if([key isEqualToString:kLocal_Alert_Coin]){
        settings.showCoinAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Assist]){
        settings.showAssistAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Part_Assist]){
        settings.showPartAssistAlert = [value intValue]>0;

    }else if([key isEqualToString:kLocal_Alert_Beg]){
        settings.showBegAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Work]){
        settings.showWorkAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Touch]){
        settings.showTouchAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Gift_Touch]){
        settings.showGiftTouchAlert = [value intValue]>0;

    }else if([key isEqualToString:kLocal_Alert_Diary_Vote]){
        settings.showDiaryVoteAlert = [value intValue]>0;

    }else if([key isEqualToString:kLocal_Alert_Friend_Publish]){
        settings.showFriendPublishAlert = [value intValue]>0;

    }else if([key isEqualToString:kLocal_Alert_Part_Publish]){
        settings.showPartPublishAlert = [value intValue]>0;

    }else if([key isEqualToString:kLocal_Alert_Work_Publish]){
        settings.showWorkPublishAlert = [value intValue]>0;

    }else if([key isEqualToString:kLocal_Alert_Barb_Publish]){
        settings.showBarbPublishAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Present]){
        settings.showPresentAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Service]){
        settings.showServiceAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_ServiceLocal]){
        settings.showServiceLocalAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_OtherFish]){
        settings.showOtherFishAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_JinlongFish]){
        settings.showJinlongFishAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_FreeFish]){
        settings.showFreeFishAler= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Crowd]){
        settings.showCrowdAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_luck]){
        settings.showLuckAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_GiftRoomFeed]){
        settings.showGiftRoomFeedAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Pole_Water]){
        settings.showPoleWaterUsingAlert= [value intValue]>0;
        
    }else if ([key isEqualToString:kLocal_Alert_Tower_playTips]) {
        settings.showHandsCardsAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Mall_Notice]){
        settings.showMallNoticeAlert= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Work_Diary_Check]){
        settings.showWorkDiaryCheckAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Expense_Fish]){
        settings.showExpenseFishAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_Mission_Out]){
        settings.showMissionOutAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Alert_StepWarn]){
        settings.showStepWarnAlert = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_CachePoolRobShake]){
        settings.cache_Pool_RobShake= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_CachePoolTraffic]){
        settings.cachePoolTraffic= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Ignore_Circle_Rank]){
        settings.ignoreCircleRank = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Ignore_Circle_Shared]){
        settings.ignoreCircleShared = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Is_Upload_Addressbook]){
        settings.isUploadAddressBook = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_Is_First_Login]){
        settings.isFirstLogin = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_HasNewWorker]){
        settings.hasNewWorker = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_IsAutoGetFish]){
        settings.isAutoGetFish = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_IsTouchHighLight]){
        settings.isTouchHighLight = [value intValue]>0;
    }else if([key isEqualToString:kLocal_CachePoolRobID]){
        settings.cache_Pool_RobID = value;
        
    }else if([key isEqualToString:kLocal_CachePoolRobPet]){
        settings.cache_Pool_RobPet = value;
        
    }else if([key isEqualToString:kLocal_CachePoolPushPet]){
        settings.cachePoolPushPet = value;
        
    }else if([key isEqualToString:kLocal_CacheBuddhaPestle]){
        settings.cacheBuddhaPestle = value;
        
    }else if([key isEqualToString:kLocal_CacheBuddhaIncense]){
        settings.cacheBuddhaIncense = value;
        
    }else if([key isEqualToString:kLocal_CacheBuddhaIncenseText]){
        settings.cacheBuddhaIncenseText = value;
        
    }else if([key isEqualToString:kLocal_CacheWalkEndTime]){
        settings.cacheWalkEndTime = [value integerValue];
        
    }else if([key isEqualToString:kLocal_CacheCalendarDispDate]){
        settings.cacheCalendarDispDate = value;
        
    }else if([key isEqualToString:kLocal_CacheCalendarDisp]){
        settings.cacheCalendarDisp = [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_CacheNetsShareFishDispDate]){
        settings.cacheNetsShareFishDispDate = value;
        
    }else if([key isEqualToString:kLocal_CacheBillLastPrinterGUID]){
        settings.cacheBillLastPrinterGUID = value;
        
    }else if ([key isEqualToString:kLocal_CacheBillInvitionCode]){
        settings.cacheBillInvitionCode = value;
    }
    else if ([key isEqualToString:kLocal_CacheBillEntityCode]){
        settings.cacheBillEntityCode = value;
        
    }else if([key isEqualToString:kLocal_CacheCollectionTimeDispDate]){
        settings.cacheCollectionTimeDispDate = value;
        
    }else if([key isEqualToString:kLocal_CachePoolPushBag]){
        settings.cachePoolPushBag = value;
        
    }else if([key isEqualToString:kLocal_CachePoolPushVirtual]){
        settings.cachePoolPushVirtual= [value intValue]>0;
        
    }else if([key isEqualToString:kLocal_CachePoolPushUmbrella]){
        settings.cachePoolPushUmbrella= [value intValue]>0;
        
    }else if ([key isEqualToString:kLocal_CacheTowerPlayCardsCountdown]) {
        settings.cacheTowerPlayCardsCountdown = value;
        
    }else if ([key isEqualToString:kLocal_CacheLastFishRecycleTime]) {
        settings.cacheLastFishRecycleTime = value;
        
    }else if ([key isEqualToString:kLocal_DataClean]) {
        settings.dataClean = [value intValue];
        
    }else if ([key isEqualToString:kLocal_CacheBarbGuide]) {
        settings.hasShowHelpBardGuide = [value integerValue] > 0;
        
    }else if ([key isEqualToString:kLocal_CacheCenterGuide]) {
        settings.hasShowHelpCenterGuide = [value integerValue] > 0;
        
    }else if ([key isEqualToString:kLocal_CacheWorkEntityCode]){
        settings.cacheWorkEntityCode = value;
        
    }else if ([key isEqualToString:kLocal_CacheWorkEntitySel]){
        settings.cacheWorkEntitySel = [value longLongValue];
        
    }else if ([key isEqualToString:kLocal_CacheSpiritSel]){
        settings.cacheSpiritEntitySel = [value longLongValue];

    }else if ([key isEqualToString:kLocal_CacheLiveSel]){
        settings.cacheLiveSel = [value longLongValue];
        
    }else if ([key isEqualToString:kLocal_CacheLastVersion]){
        settings.lastVersionNum = [value intValue];
        
    }else if ([key isEqualToString:kLocal_CacheBrushPictureCount]) {
        settings.cacheBrushPictureCount = value;
        
    }else if ([key isEqualToString:kLocal_CacheStepUploadingTime]) {
        settings.cacheStepUploadingTime = [value intValue];
        
    }else if ([key isEqualToString:kLocal_CacheStepRemain]) {
        settings.cacheStepRemain = [value intValue];
        
    }else if ([key isEqualToString:kLocal_CacheTraceRoom]) {
        settings.cacheTraceRoom = [value longLongValue];
        
    }else if ([key isEqualToString:kLocal_CachePokeeMaster]) {
        settings.cachePokeeMaster = [value longLongValue];
        
    }else if ([key isEqualToString:kLocal_CachePokeeTime]) {
        settings.cachePokeeTime = [value intValue];
        
    }else if ([key isEqualToString:kLocal_CachePokeeRoom]) {
        settings.cachePokeeRoom = [value longLongValue];
        
    }else if ([key isEqualToString:kLocal_CacheMainFlag]) {
//        settings.cacheMainFlag = [value intValue];
        
    }else if ([key isEqualToString:kLocal_CacheTerminateTime]) {
        settings.cacheTerminateTime = [value intValue];
        
    }else if ([key isEqualToString:kLocal_CacheAskContact]) {
        settings.hasAskContacts = [value intValue]>0;
        
    }else if ([key isEqualToString:kLocal_CacheAskActivity]) {
        settings.hasAskActivity = [value integerValue]>0;
        
    }else if ([key isEqualToString:kLocal_CacheExpenseSelectRole]) {
        settings.cacheSelectRoleEntityCode = value;
        
    }else if ([key isEqualToString:kLocal_CacheUpdateContact]) {
        settings.hasUpdateContact = [value integerValue]>0;
    }else if ([key isEqualToString:kLocal_CacheNewFeature]) {
        settings.feature = [value intValue];
    }else if ([key isEqualToString:kLocal_CacheSourceFlag]) {
        settings.cacheSourceFlag = [value intValue];
    }else if ([key isEqualToString:kLocal_CacheQRStyle]) {
        settings.cacheQRStyle = [value intValue];
    }else if ([key isEqualToString:kLocal_CacheCopyFile]) {
        settings.hasCopyFile = [value intValue]>0;
    }
    
    // 新帮助弹框
    else if ([key isEqualToString:kLocal_CacheShowSpirit]) {
        settings.hasShowHelpSpirit = [value intValue]>0;
    }else if ([key isEqualToString:kLocal_CacheShowSpiritAR]) {
        settings.hasShowHelpSpiritAr = [value intValue]>0;
    }
    // 黄金积分
    else if ([key isEqualToString:kLocal_CacheGMCenterPoint]) {
        settings.cacheGMCenterPoint = [value longLongValue];
    }else if ([key isEqualToString:kLocal_CacheShowThirdRed]) {
        settings.hasShowThirdRed = [value intValue]>0;
    }else if ([key isEqualToString:kLocal_CacheGMTargetPoint]) {
        settings.cacheGMTargetPoint = [value longLongValue];
    }else if ([key isEqualToString:kLocal_CacheJDUID]) {
        settings.cacheJDUID = value;
    }
}



@end

@implementation AFFThemeConfig

static AFFThemeConfig *instance = nil;

+ (AFFThemeConfig *) sharedInstance {
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{ instance = [[AFFThemeConfig alloc]init]; [instance initStatic]; });
    
    return instance;
}

// 静态配置
- (void)initStatic{
    // 注意前面都是静态的
    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
    self.identifier = [infoDict stringForKey:@"CFBundleIdentifier"];
    self.runingMode = [infoDict charForKey:@"AnyfishRunningModel"];
    
    self.versionStr = [infoDict objectForKey:@"CFBundleShortVersionString"];
    self.versionBuild = [infoDict objectForKey:@"CFBundleVersion"];
    self.versionNum = [[NSString stringWithFormat:@"%@", [self.versionStr stringByReplacingOccurrencesOfString:@"." withString:@""]] intValue];
    if(self.versionNum<100){
        self.versionNum *=10;
    }
    

    _cacheMainFlag = [_identifier isEqualToString:kBundleID_AS_radio]?2:[_identifier isEqualToString:kBundleID_AF_AppStore]?3:0;
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSNumber *number = [user objectForKey:@"cacheMainFlag"];
    if(number){
        _cacheMainFlag = number.intValue;
    }
    

    // 其他静态资源
    CGFloat delta = ScreenScale>2?1:0;
    _fontSize_8 = 8.0f + delta;
    _fontSize_9 = 9.0f + delta;
    _fontSize_10 = 10.0f + delta;
    _fontSize_11 = 11.0f + delta;
    _fontSize_12 = 12.0f + delta;
    _fontSize_13 = 13.0f + delta;
    _fontSize_14 = 14.0f + delta;
    _fontSize_15 = 15.0f + delta;
    _fontSize_16 = 16.0f + delta;
    _fontSize_17 = 17.0f + delta;
    _fontSize_18 = 18.0f + delta;
    _fontSize_19 = 19.0f + delta;
    _fontSize_21 = 21.0f + delta;
    
    _color_21292c = [UIColor colorWithARGBString:@"#21292c"];
    _color_16a8ef = [UIColor colorWithARGBString:@"#16a8ef"];
    _color_ffffff = [UIColor colorWithARGBString:@"#ffffff"];
    _color_666666 = [UIColor colorWithARGBString:@"#666666"];
    _color_999999 = [UIColor colorWithARGBString:@"#999999"];
//    _color_333333 = [UIColor colorWithARGBString:@"#333333"];
    _color_333333 = [UIColor colorWithARGBString:@"#000000"];
//    _color_333333 = [UIColor colorWithARGBString:@"#444444"]; // 导航是金色才用
    _color_d7d7d7 = [UIColor colorWithARGBString:@"#d7d7d7"];
    _color_e7e7e7 = [UIColor colorWithARGBString:@"#e7e7e7"];
    _color_1fa4ff = [UIColor colorWithARGBString:@"#1fa4ff"];
    _color_f44336 = [UIColor colorWithARGBString:@"#f44336"];
    _color_eeeeee = [UIColor colorWithARGBString:@"#eeeeee"];
    _color_f8f8f8 = [UIColor colorWithARGBString:@"#f8f8f8"];
    _color_ff9800 = [UIColor colorWithARGBString:@"#ff8800"];
    _color_77c8f0 = [UIColor colorWithARGBString:@"#77c8f0"];
    _color_7d94f4 = [UIColor colorWithARGBString:@"#7d94f4"];
    _color_81c026 = [UIColor colorWithARGBString:@"#81c026"];
    _color_cdf6fd = [UIColor colorWithARGBString:@"#cdf6fd"];
    _color_f3e14f = [UIColor colorWithARGBString:@"#f3e14f"];
    _color_f7dc26 = [UIColor colorWithARGBString:@"#f7dc26"];
    _color_69d0d0 = [UIColor colorWithARGBString:@"#69d0d0"];
    _color_ff8381 = [UIColor colorWithARGBString:@"#ff8381"];
    _color_f0f4f7 = [UIColor colorWithARGBString:@"#f0f4f7"];
    _color_ef8692 = [UIColor colorWithARGBString:@"#ef8692"];
    _color_76ad00 = [UIColor colorWithARGBString:@"#76ad00"];
    _color_a5a8ac = [UIColor colorWithARGBString:@"#a5a8ac"];
    
    // 鱼符
    _color_ff7573 = [UIColor colorWithARGBString:@"#ff7573"];
    _color_59d7a9 = [UIColor colorWithARGBString:@"#59d7a9"];
    _color_ffae20 = [UIColor colorWithARGBString:@"#ffae20"];
    _color_43c6f3 = [UIColor colorWithARGBString:@"#43c6f3"];
    _color_e5e5e5 = [UIColor colorWithARGBString:@"#e5e5e5"];
    _color_e28701 = [UIColor colorWithARGBString:@"#e28701"];
    _color_fab91c = [UIColor colorWithARGBString:@"#fab91c"];
    
    // 商城
    _color_d7ac6b = [UIColor colorWithARGBString:@"#d7ac6b"];
    _color_eccd8e = [UIColor colorWithARGBString:@"#eccd8e"];
    _color_cca76e = [UIColor colorWithARGBString:@"#cca76e"];
    _color_2984e9 = [UIColor colorWithARGBString:@"#2984e9"];
    
    _height_Separate  =  ScreenScale>2.0 ? 0.35f : 0.5f;
    
}


- (BOOL)isInhouse {
    return ![self.identifier isEqualToString:kBundleID_AF_AppStore] &&
    ![self.identifier isEqualToString:kBundleID_AF_Street] &&
    ![self.identifier isEqualToString:kBundleID_AS_radio] &&
    ![self.identifier isEqualToString:kBundleID_AS_lzgxt];
}

- (BOOL)isCenterLive {
    return [kSetting.identifier isEqualToString:kBundleID_WHBL];
}

- (BOOL)isRadio {
    return self.cacheMainFlag>0 && self.cacheMainFlag<=2; 
}

- (NSString*)downloadUrl_AppStore {
    NSString *appid = nil;
    if([self.identifier isEqualToString:kBundleID_AF_AppStore]){
        appid = @"https://itunes.apple.com/us/app/bai-yu/id881852185?l=zh&ls=1&mt=8";
    }else if([self.identifier isEqualToString:kBundleID_AF_Street]){
        appid = @"https://itunes.apple.com/us/app/hou-shang/id1155887972?l=zh&ls=1&mt=8";
    }else if([self.identifier isEqualToString:kBundleID_AS_lzgxt]){
        appid = @"https://itunes.apple.com/us/app/gong-xin-tong/id1182299769?l=zh&ls=1&mt=8";
    }else if([self.identifier isEqualToString:kBundleID_AS_radio]){
        appid = @"https://itunes.apple.com/us/app/radio/id1225858154?l=zh&ls=1&mt=8";
    }else if([self.identifier isEqualToString:kBundleID_AF_Mall]){
        appid = @"https://itunes.apple.com/us/app/goldmall/id1228450377?l=zh&ls=1&mt=8";
    }
    
    return appid;
}

- (void)setCacheMainFlag:(U8)cacheMainFlag {
    _cacheMainFlag = cacheMainFlag;
    
    // 更新到user
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:@(cacheMainFlag) forKey:@"cacheMainFlag"];
    [user synchronize];
}

#pragma mark 颜色


- (UIColor*)color_Title {
    return self.color_333333;
}

- (UIColor*)color_Content {
    return self.color_999999;
}

- (UIColor*)color_Text {
    return self.color_333333;
}

- (UIColor*)color_NavTitle {
    return self.color_333333;
}

- (UIColor*)color_Notify {
    return self.color_ffffff;
}

- (UIColor*)color_Sign {
    return self.color_666666;
}

- (UIColor*)color_Sign_Sel {
    return self.color_16a8ef;
}

- (UIColor*)color_Section {
    return self.color_Bg_VC;
}

- (UIColor*)color_Section_Text {
    return self.color_666666;
}

- (UIColor*)color_Separate {
    return self.color_d7d7d7;
}

- (UIColor*)color_Badge {
    return self.color_f44336;
}

- (UIColor*)color_Chat_Sub {
    return _color_999999;
}

- (UIColor*)color_Chat_TimeStamp {
    return _color_a5a8ac;
}

- (UIColor*)color_Chat_Title {
    return self.color_333333;
}

- (UIColor*)color_Chat_Desc {
    return self.color_999999;
}

- (UIColor*)color_Chat_Info_Bg {
    return [UIColor colorWithARGBString:@"#000000" alpha:0.15];
}

- (UIColor*)color_Chat_Title_Sel {
    return self.color_333333;
}

- (UIColor*)color_Chat_Title_Out {
    return self.color_333333;
}

- (UIColor*)color_Chat_Title_Out_Sel {
    return self.color_333333;
}

- (UIColor*)color_Bg_Nav {
    return KUIColorARGBString(@"#5EB8E9");
}

- (UIColor*)color_Bg_Sta {
    return KUIColorARGBString(@"#5EB8E9");
}

- (UIColor*)color_Bg_Search {
    return self.color_e7e7e7;
}

- (UIColor*)color_Bg_TabVCell {
    return self.color_ffffff;
}

- (UIColor*)color_Bg_VC {
    if(kSetting.cacheMainFlag==3)
        return [UIColor colorWithARGBString:@"#f5f5f5"];
    
    return self.color_e7e7e7;
}

- (UIColor*)color_Bg_Image {
    return _cacheMainFlag==3?self.color_Bg_VC:self.color_f0f4f7;
}

- (UIColor*)color_radio {
    return self.color_ef8692;
}

- (UIColor*)color_Bg_Tab {
    return KUIColorARGBString(@"#F7F7F7");
}

- (UIColor*)color_Bg_TableView {
    return [UIColor clearColor];
}

- (UIColor*)color_Bg_Chat {
    return self.color_eeeeee;
}

- (UIColor*)color_Btn_Blue {
    return self.color_16a8ef;
}

- (UIColor*)color_Btn_Disabled {
    return self.color_d7d7d7;
}

- (UIColor*)color_Btn_Orange {
    return self.color_ff9800;
}

- (UIColor*)color_Btn_Red {
    return self.color_f44336;
}

- (UIColor*)color_Btn_Green {
    return self.color_69d0d0;
}

- (UIColor*)color_16a8ef {
    if(self.isRadio)
        return _color_ef8692;
    else if(_cacheMainFlag==3)
        return _color_cca76e;
    else
        return _color_16a8ef;
}

- (UIColor*)color_ff9800 {
    if(self.isRadio)
        return _color_ff9800;
    else
        return _color_ff9800;
}

- (UIColor*)color_Redbag {
    return [UIColor colorWithARGBString:@"#2d343e"];
}

- (UIColor*)color_RedbagText {
    return [UIColor colorWithARGBString:@"#c3976a"];
}

- (UIColor*)color_TBao {
    return [UIColor colorWithARGBString:@"#2d2c32"];
}

#pragma mark 字体

- (UIFont*)font_8 {
    return [UIFont fontWithSize_M:_fontSize_8];
}

- (UIFont*)font_9 {
    return [UIFont fontWithSize_M:_fontSize_9];
}

- (UIFont*)font_10 {
    return [UIFont fontWithSize_M:_fontSize_10];
}

- (UIFont*)font_11 {
    return [UIFont fontWithSize_M:_fontSize_11];
}

- (UIFont*)font_12 {
    return [UIFont fontWithSize_M:_fontSize_12];
}

- (UIFont*)font_13 {
    return [UIFont fontWithSize_M:_fontSize_13];
}

- (UIFont*)font_14 {
    return [UIFont fontWithSize_M:_fontSize_14];
}

- (UIFont*)font_15 {
    return [UIFont fontWithSize_M:_fontSize_15];
}

- (UIFont*)font_16 {
    return [UIFont fontWithSize_M:_fontSize_16];
}

- (UIFont*)font_17 {
    return [UIFont fontWithSize_M:_fontSize_17];
}

- (UIFont*)font_18 {
    return [UIFont fontWithSize_M:_fontSize_18];
}

- (UIFont*)font_19 {
    return [UIFont fontWithSize_M:_fontSize_19];
}

- (UIFont*)font_21 {
    return [UIFont fontWithSize_M:_fontSize_21];
}

- (UIFont*)font_Title {
    return self.font_17;
}

- (UIFont*)font_Content {
    return self.font_14;
}

- (UIFont*)font_Notify {
    return self.font_11;
}

- (UIFont*)font_Sign {
    return self.font_10;
}

- (UIFont*)font_Section {
    return self.font_12;
}

- (UIFont*)font_Chat_Title {
    return self.font_16;
}

- (UIFont*)font_Chat_Desc {
    return self.font_12;
}

- (UIFont*)font_Chat_Info {
    return self.font_12;
}

- (UIFont*)font_Title_Big {
    return [UIFont fontWithSize_S:SCREEN_WIDTH>SCREEN_WIDTH?_fontSize_18:_fontSize_16];
}

- (UIFont*)font_Text {
    return self.font_14;
}

- (UIFont*)font_Button {
    return self.font_15;
}

- (UIFont*)font_Address {
    return self.font_10;
}

- (UIFont*)font_Location {
    return self.font_15;
}

- (UIFont*)font_NavItem {
    return SCREEN_WIDTH<SCREEN_WIDTH?self.font_15:self.font_16;
}

- (UIFont*)font_AlertButton {
    return self.font_Button;
}

- (UIFont*)font_AlertDesc {
    return self.font_11;
}

- (UIFont*)font_AlertInput {
    return self.font_13;
}

- (UIFont*)font_AlertSheet {
    return self.font_17;
}

- (UIFont*)font_AlertTitle {
    return self.font_15;
}


#pragma mark globle路径配置

- (NSString*)path_Exception {
   return [NSString stringWithFormat:@"%@/Exception",[self path_Globle]];
}

- (NSString*)path_Event {
    return [NSString stringWithFormat:@"%@/Event",[self path_Globle]];
}

- (NSString*)path_Location {
    return [NSString stringWithFormat:@"%@/Location",[self path_Globle]];
}

- (NSString*)path_Url {
    return [NSString stringWithFormat:@"%@/Url",[self path_Globle]];
}

- (NSString*)path_Download {
    return [NSString stringWithFormat:@"%@/Download",[self path_Globle]];
}

- (NSString*)path_MediaTempSelect {
    return [NSString stringWithFormat:@"%@/Media/TempSelect",[self path_Globle]];
}

- (NSString*)path_ImageTransfer {
    return [NSString stringWithFormat:@"%@/Media/ImageTransfer",[self path_Globle]];
}


@end
